<template>
</template>

<script>
	export default {

		data() {
			return {

			}
		},
		onLoad() {
			this.getSocket();
		},
		methods: {
			getSocket() {
				const app = this
				uni.connectSocket({
					url: 'ws://push.mall.laravelvip.com:4431'
				});
				uni.onSocketOpen(function(res) {
					console.log('WebSocket连接已打开！');
					app.socketOpen = true;

					let msg = {
						"room_id": "3",
						"total_num_init": "46",
						"type": "live_login_set",
						"url": "ws://push.mall.laravelvip.com:4431",
						"user_headimg": "http://image.laravelvip.com/images/site/1/images/2018/06/03/15280050844047.png",
						"user_id": "0r3kc6jkp618jmd8vchv2vvtap",
						"user_name": "游客_0r3kc6jkp6"
					};
					msg = JSON.stringify(msg)
					uni.sendSocketMessage({
						// data: '{"type":"ping"}'
						data: msg
					});
				});

				uni.onSocketMessage(function(res) {
					console.log('收到服务器内容：' + res.data);
				});

				uni.onSocketClose(function(res) {
					console.log('WebSocket 已关闭！');
				});

				uni.onSocketError(function(res) {
					console.log('WebSocket连接打开失败，请检查！');
				});
			},
		}
	}
</script>

<style>
</style>
